<?php

namespace App\Http\Controllers\Customer;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Facades\Services\AddressService;
use ValiDate;

class AddressController extends Controller
{
    public function getAddress(){
    	return formatJsonResponse(AddressService::getAddress());
    }

    public function addAddress(Request $request){

    	$rules = [
    		'address' => 'required'
    	];

    	ValiDate::validate($request,$rules);

    	$data=$request->all();

    	return formatJsonResponse(AddressService::addAddress($data));
    }

    public function updateAddress(Request $request){
    	$rules = [
    		'id' => 'required|exists:addresses,id',
    		'address' => 'required'
    	];

    	ValiDate::validate($request,$rules);

    	$data = $request->all();

    	return formatJsonResponse(AddressService::updateAddress($data));
    }

    public function deleteAddress(Request $request){
        $rules = [
            'id' => 'required|exists:addresses,id'
        ];

        ValiDate::validate($request,$rules);

        $data = $request->all();

        return formatJsonResponse(AddressService::deleteAddress($data));
    }
}
